package com.chanyachting.emall.action.newsactivity;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.chanyachting.emall.domain.Newsactivity;
import com.chanyachting.emall.form.NewsActivityForm;
import com.chanyachting.emall.service.NewsActivityService;
import com.chanyachting.emall.serviceImpl.NewsActivityServiceImpl;

public class QueryActivityDetailsAction extends Action {

	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {

		NewsActivityForm naForm=(NewsActivityForm)form;
		
		NewsActivityService naservice=new NewsActivityServiceImpl();
		
		String id = request.getParameter("newsid");
		id = id == null ? "" : id;
		
		Integer newsid = Integer.parseInt(id);
		
		List list = naservice.getNewsActivityByNewsid(newsid);
		
		Integer readNums = ((Newsactivity)list.get(0)).getReadNums();
		readNums = new Integer(readNums.intValue() + 1);
		naservice.updateReadNums(newsid, readNums);
		
		naForm.setList(list);
		
		return mapping.findForward("newsActivityDetails");
	}

}
